package org.example.leetcode.core.mq;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName RabbitmqConfig
 * @Description TODO
 * @Author 胡泽
 * @Date 2019/12/17 12:35
 * @Version 1.0
 */
@Configuration
public class RabbitmqConfig {

    public static final String QUEUE_RECOMMEND = "queue_recommend";
    public static final String EXCHANGE="exchange";
    public static final String ROUTINGKEY_RECOMMEND="recommend";

    //声明交换机
    @Bean(EXCHANGE)
    public Exchange EXCHANGE_TOPICS_INFORM(){
        //durable(true) 持久化，mq重启之后交换机还在
        return ExchangeBuilder.topicExchange(EXCHANGE).durable(true).build();
    }

    @Bean(QUEUE_RECOMMEND)
    public Queue QUEUE_INFORM_EMAIL(){
        return new Queue(QUEUE_RECOMMEND);
    }

    @Bean
    public Binding BINDING_QUEUE_INFORM_EMAIL(@Qualifier(QUEUE_RECOMMEND) Queue queue,
                                              @Qualifier(EXCHANGE) Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_RECOMMEND).noargs();
    }

}